#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int minOperations(vector<int>& nums) {
        int res = 0;
        int i = 0, n = nums.size();
        while (i < n - 2)
        {
            if (nums[i] == 0)
            {
                nums[i] = 1 - nums[i];
                nums[i + 1] = 1 - nums[i + 1];
                nums[i + 2] = 1 - nums[i + 2];
                ++res;
            }
            ++i;
        }
        if (nums[i] == nums[i + 1] && nums[i] == 1) return res;
        else return -1;
    }
};